import 'package:flutter/material.dart';

class FirstPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _FirstPageState();
  }
}

class _FirstPageState extends State<FirstPage> {
  String msg = "";
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("first page"),
        centerTitle: true,
      ),
      body: Center(
        child: Column(
          children: [
            TextButton(
              /// 使用Navigator进行传输数据，放入pushNamed中，作为arguments，使用then接收返回参数
              onPressed: () => Navigator.of(context).pushNamed('second',
                  arguments: ['aaaa', 'bbbb']).then((value) {
                setState(() {
                  /// 得到一个返回的参数
                  this.msg = value;
                });
              }),
              child: Row(
                children: [
                  Flexible(
                      child: Text(
                          "turn to page second with message on second page: $msg")),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }
}
